import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    meta: {
      title: "首页",
      icon: 'el-icon-s-home',
    },
    name: 'index',
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/home.vue'),
        meta: {
          title: "首页",
        }
      },
    ]
  },
  {
    path: '/banner',
    component: Layout,
    meta: {
      title: "轮播管理",
      icon: 'el-icon-s-home',
    },
    name: 'banner',
    children: [
      {
        path: 'list',
        name: 'bannerList',
        component: () => import('@/views/banner/index.vue'),
        meta: {
          title: "轮播管理",
        }
      },
    ]
  },
  {
    path: '/coupon',
    component: Layout,
    meta: {
      title: "优惠券管理",
      icon: 'el-icon-s-home',
    },
    name: 'coupon',
    children: [
      {
        path: 'list',
        name: 'couponList',
        component: () => import('@/views/coupon/index.vue'),
        meta: {
          title: "优惠券管理",
        }
      },
      {
        path: 'user-list',
        name: 'userCouponList',
        component: () => import('@/views/userCoupon/index.vue'),
        meta: {
          title: "用户优惠券",
        }
      },
    ]
  },
  {
    path: '/product',
    component: Layout,
    meta: {
      title: "门票管理",
      icon: 'el-icon-s-home',
    },
    name: 'product',
    children: [
      // {
      //   path: 'category',
      //   name: 'productCategoryList',
      //   component: () => import('@/views/category/index.vue'),
      //   meta: {
      //     title: "门票分类",
      //   }
      // },
      {
        path: 'shop-list',
        name: 'ticketShopList',
        component: () => import('@/views/ticketShop/index.vue'),
        meta: {
          title: "景点管理",
        }
      },
      {
        path: 'list',
        name: 'productList',
        component: () => import('@/views/product/index.vue'),
        meta: {
          title: "门票管理",
        }
      },
      {
        path: 'line-list',
        name: 'ticketLineList',
        component: () => import('@/views/ticketLine/index.vue'),
        meta: {
          title: "线路管理",
        }
      },
    ]
  },
  {
    path: '/order',
    component: Layout,
    meta: {
      title: "订单管理",
      icon: 'el-icon-s-home',
    },
    name: 'cdk',
    children: [
      {
        path: 'list',
        name: 'orderList',
        component: () => import('@/views/order/index.vue'),
        meta: {
          title: "订单管理",
        }
      },
    ]
  },
  {
    path: '/member',
    component: Layout,
    meta: {
      title: "会员管理",
      icon: 'el-icon-s-home',
    },
    name: 'member',
    children: [
      {
        path: 'list',
        name: 'memberList',
        component: () => import('@/views/member/index.vue'),
        meta: {
          title: "会员管理",
        }
      },
    ]
  },
    // 帖子
  {
    path: '/post',
    component: Layout,
    meta: {
      title: "帖子管理",
      icon: 'el-icon-s-home',
    },
    name: 'post',
    children: [
      {
        path: 'list',
        name: 'postList',
        component: () => import('@/views/post/index.vue'),
        meta: {
          title: "帖子管理",
        }
      },
      {
        path: 'comment',
        name: 'commentList',
        component: () => import('@/views/postComment/index.vue'),
        meta: {
          title: "评论管理",
        }
      }
    ]
  },
  {
    path: '/distribution',
    component: Layout,
    meta: {
      title: "分销管理",
      icon: 'el-icon-s-home',
    },
    name: 'distribution',
    children: [
      // {
      //   path: 'list',
      //   name: 'distributionList',
      //   component: () => import('@/views/distribution/index.vue'),
      //   meta: {
      //     title: "分销比例",
      //   }
      // },
      {
        path: 'balance',
        name: 'balanceRecordList',
        component: () => import('@/views/balanceRecord/index.vue'),
        meta: {
          title: "余额记录",
        }
      }
    ]
  },
  {
    path: '/file',
    component: Layout,
    meta: {
      title: "文件管理",
      icon: 'el-icon-s-home',
    },
    name: 'file',
    children: [
      {
        path: 'file',
        name: 'file',
        component: () => import('@/views/file/index.vue'),
        meta: {
          title: "文件管理",
        }
      },
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
